        <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *,
        body {
            margin: 0;
            padding: 0;
        }

        body {
            display: flex;
            justify-content: start;
            align-items: center;
            min-height: 100vh;
            flex-wrap: nowrap;
        }

        ul,
        li {
            list-style: none;
        }

        a {
            text-decoration: none;
            color: #333;
        }

        a:hover {
            color: lightgreen;
        }

        .box {
            position: absolute;
            left: 20%;
            border: 3px groove #1a2d3c;
            width: 300px;
            height: 300px;
        }
        .content{
            position: relative;
        }
        .event{
            position: absolute;
            width: 100%;
            height: 100%;
            z-index: 999;
        }
        .mask{
            position: absolute;
            width: 100px;
            height: 100px;
            background: rgba(126,126,126,.5);
            z-index: 998;
            opacity: 0;
        }
        .big{
            position: absolute;
            top: 0;
            right: -600px;
            width: 300px;
            height: 300px;
            overflow: hidden;
            border: 3px groove #1a2d3c;
            opacity: 0;
        }
        .big img{
            position: absolute;
            width: 600px;
            height: 600px;
        }
    </style>
</head>

<body>
    <!-- 不做缩略图了,原理一样 -->

    <div class="box">
        <div class="event"></div>
        <div class="mask"></div>
        <div class="small"><img src="./小图.png"></div>
        <div class="big"><img src="./大图.png"></div>
    </div>
    <script>
        var content = document.querySelector('.content')
    </script>
</body>

<script>
    var box = document.querySelector('.box')
    var mask = document.querySelector('.mask')
    var big = document.querySelector('.big')
    var event = document.querySelector('.event')
    
    box.addEventListener('mouseenter',()=>{
        mask.style.opacity = 1
        big.style.opacity = 1
    })
    box.addEventListener('mouseleave',()=>{
        mask.style.opacity = 0
        big.style.opacity = 0
    })
    box.addEventListener('mousemove',(e)=>{
        startX = box.offsetLeft;
        startY = box.offsetTop;

        endX = e.x - box.offsetLeft - mask.offsetWidth/2 ;
        endY = e.y - box.offsetTop - mask.offsetHeight/2 ;

        // 这里-1,-3是因为盒子被撑大了
        // 而我找不到哪里给撑开的
        if(endX < -1){
            endX = -1
        }else if(endX > box.offsetWidth-mask.offsetWidth-3){
            endX = box.offsetWidth-mask.offsetWidth-3
        }
        if(endY < -1){
            endY = -1
        }else if(endY > box.offsetHeight-mask.offsetHeight-3){
            endY = box.offsetHeight-mask.offsetHeight-3
        }

        mask.style.left = endX + 'px';
        mask.style.top = endY   + 'px' ;

        big.children[0].style.left = -2 * endX + 'px';
        big.children[0].style.top = -2 * endY + 'px';
    })
</script>
</html>
